package cn.lanqiao.servlet;

import cn.lanqiao.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//@WebServlet("/user")
public class UserServlet extends HttpServlet {

    public UserServlet(){
        System.out.println("实例化操作！");
    }

    @Override
    public void init(){
        System.out.println("初始化方法！");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("登录验证");
        System.out.println(request.getParameter("key"));
        if(true) {
            //访问UserDao获得数据
            List list = new UserDao().query("select id,user_name,password from sys_user");
            //将list对象转发到jsp。
            request.setAttribute("userList", list);
            request.getRequestDispatcher("list.jsp").forward(request, response);//转发
        }else{
            //login.jsp
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    public void destroy(){
        System.out.println("销毁操作");
    }
}
